<template>
  <div class="home-hot" ref="target">
    <HomePanel title="人气推荐" subTitle="人气爆款 不容错过">
      <template #right><XtxMore path="/" /></template>
      <transition name="fade">
        <!-- 面板内容 -->
        <ul v-if="goods.length" class="goods-list">
          <li v-for="item in goods" :key="item.id">
            <RouterLink to="/">
              <img :src="item.picture" alt="">
              <p class="name ellipsis">{{item.title}}</p>
              <p class="desc">{{item.alt}}</p>
            </RouterLink>
          </li>
        </ul>
        <!-- 骨架屏 -->
        <HomeSkeleton v-else/>
      </transition>
    </HomePanel>
  </div>
</template>

<script setup>
import { findHot } from '@/api/home'
import HomePanel from './home-panel.vue'
import HomeSkeleton from './home-skeleton.vue'
import { useLazyData } from '@/hooks'

// 监听元素是否出现在可视区域
const { target, result: goods } = useLazyData(findHot)

</script>

<style lang="scss" scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 426px;
    // background: #f0f9f4;
    @include hoverShadow;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
.fade{
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity .1s .2s;
      z-index: 1;
    }
    &-to {
      opacity: 0;
    }
  }
}
</style>
